﻿Public Class MengenVerfallsDatumUC

#Region " D e k l a r a t i o n e n "
    Public Event MengenÄnderung(Menge As Integer)
    Public Event DatumsÄnderung(Datum As Date)
    Private _Datum As Date = Now
#End Region

#Region " E i g e n s c h a f t e n "
    Private ReadOnly Property Menge As Integer
        Get
            Return CInt(Me.TextBoxMenge.Text)
        End Get
    End Property
    Private ReadOnly Property Datum As Date
        Get
            Return _Datum
        End Get
    End Property
#End Region

#Region " Public Sub SetzeMenge "
    Public Sub SetzeMenge(NeueMenge As Integer)
        Me.TextBoxMenge.Text = NeueMenge
    End Sub
#End Region

#Region " Public Sub SetzeDatum "
    Public Sub SetzeDatum(NeuesDatum As Date)
        Me.TextBoxTag.Text = NeuesDatum.Day
        Me.TextBoxMonat.Text = NeuesDatum.Month
        Me.TextBoxJahr.Text = NeuesDatum.Year
        _Datum = NeuesDatum
    End Sub
#End Region

#Region " Private Sub MengenVerfallsDatumUC_Load "
    Private Sub MengenVerfallsDatumUC_Load(sender As Object, e As EventArgs) Handles Me.Load
        Me.TextBoxMenge.Text = "1"
        Me.TextBoxTag.Text = Now.Day
        Me.TextBoxMonat.Text = Now.Month
        Me.TextBoxJahr.Text = Now.Year
    End Sub
#End Region

#Region " Private Sub ButtonMengePlus_Click "
    Private Sub ButtonMengePlus_Click(sender As Object, e As EventArgs) Handles ButtonMengePlus.Click
        Me.TextBoxMenge.Text = Menge + 1
        RaiseEvent MengenÄnderung(Menge)
    End Sub
#End Region

#Region " Private Sub ButtonMengeMinus_Click "
    Private Sub ButtonMengeMinus_Click(sender As Object, e As EventArgs) Handles ButtonMengeMinus.Click
        If Menge <> 0 Then
            Me.TextBoxMenge.Text = Menge - 1
            RaiseEvent MengenÄnderung(Menge)
        End If
    End Sub
#End Region

#Region " Private Sub ButtonTagPlus_Click "
    Private Sub ButtonTagPlus_Click(sender As Object, e As EventArgs) Handles ButtonTagPlus.Click
        If Datum.AddDays(1).Day <> 1 Then
            _Datum = Datum.AddDays(1)
        Else
            _Datum = Datum.AddDays(-(Datum.Day - 1))
        End If
        Me.TextBoxTag.Text = Datum.Day
        RaiseEvent DatumsÄnderung(Datum)
    End Sub
#End Region

#Region " Private Sub ButtonTagMinus_Click "
    Private Sub ButtonTagMinus_Click(sender As Object, e As EventArgs) Handles ButtonTagMinus.Click
        If Datum.Day <> 1 Then
            _Datum = Datum.AddDays(-1)
        Else
            _Datum = Datum.AddMonths(1).AddDays(-1)
        End If
        Me.TextBoxTag.Text = Datum.Day
        RaiseEvent DatumsÄnderung(Datum)
    End Sub
#End Region

#Region " Private Sub ButtonMonatPlus_Click "
    Private Sub ButtonMonatPlus_Click(sender As Object, e As EventArgs) Handles ButtonMonatPlus.Click
        If Datum.Month <> 12 Then
            _Datum = Datum.AddMonths(1)
        Else
            _Datum = Datum.AddMonths(1).AddYears(-1)
        End If
        Me.TextBoxMonat.Text = Datum.Month
        If CInt(Me.TextBoxTag.Text) <> Datum.Day Then Me.TextBoxTag.Text = Datum.Day
        RaiseEvent DatumsÄnderung(Datum)
    End Sub
#End Region

#Region " Private Sub ButtonMonatMinus_Click "
    Private Sub ButtonMonatMinus_Click(sender As Object, e As EventArgs) Handles ButtonMonatMinus.Click
        If Datum.Month <> 1 Then
            _Datum = Datum.AddMonths(-1)
        Else
            _Datum = Datum.AddMonths(-1).AddYears(1)
        End If
        Me.TextBoxMonat.Text = Datum.Month
        If CInt(Me.TextBoxTag.Text) <> Datum.Day Then Me.TextBoxTag.Text = Datum.Day
        RaiseEvent DatumsÄnderung(Datum)
    End Sub
#End Region

#Region " Private Sub ButtonJahrPlus_Click "
    Private Sub ButtonJahrPlus_Click(sender As Object, e As EventArgs) Handles ButtonJahrPlus.Click
        _Datum = Datum.AddYears(1)
        Me.TextBoxJahr.Text = Datum.Year
        RaiseEvent DatumsÄnderung(Datum)
    End Sub
#End Region

#Region " Private Sub ButtonJahrMinus_Click "
    Private Sub ButtonJahrMinus_Click(sender As Object, e As EventArgs) Handles ButtonJahrMinus.Click
        _Datum = Datum.AddYears(-1)
        Me.TextBoxJahr.Text = Datum.Year
        RaiseEvent DatumsÄnderung(Datum)
    End Sub
#End Region

End Class